package com.jzg.jcptadmin.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.data.vo.Province;

import java.util.List;

/**
 * Created by wangyd on 15/12/25.
 */
public class ProvinceAdapter extends BaseAdapter {

    private LayoutInflater inflater;

    private List<Province> list;

    public ProvinceAdapter(Context context, List<Province> list) {
        super();
        this.inflater = LayoutInflater.from(context);
        this.list = list;
    }

    @Override
    public int getCount() {

        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.simple_list_content, null);
            holder = new ViewHolder();
            holder.content = (TextView) convertView
                    .findViewById(R.id.content);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Province province = (Province) list.get(position);
        holder.content.setText(province.getName());
        holder.content.setTextColor(province.getFontColor());

        return convertView;
    }

    private class ViewHolder {
        TextView content;
    }

}
